package com.mls.medicinereminder.service.impl;

import com.mls.medicinereminder.dao.AvoidWarnDetailsMapper;
import com.mls.medicinereminder.dao.ListAvoidMapper;
import com.mls.medicinereminder.dao.ListConflictsMapper;
import com.mls.medicinereminder.dao.ListWarnMapper;
import com.mls.medicinereminder.entity.AvoidWarnDetails;
import com.mls.medicinereminder.entity.ListConflicts;
import com.mls.medicinereminder.entity.Medicine;
import com.mls.medicinereminder.service.ReminderService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;


@Service
public class ReminderServiceImpl implements ReminderService {
    @Autowired
    ListAvoidMapper avoidMapper;

    @Autowired
    ListConflictsMapper conflictsMapper;

    @Autowired
     ListWarnMapper warnMapper;

    @Autowired
    AvoidWarnDetailsMapper avoidWarnDetailsMapper;


    @Override
    public Medicine isAvoid(String record) {
        if(avoidMapper.selectByMedicineName(record)!=null){
            Medicine medicine=new Medicine();
            AvoidWarnDetails details=new AvoidWarnDetails();
            details=avoidWarnDetailsMapper.selectByMedicineName(record);
            if(details!=null){
                medicine.setName(details.getMedicinename());
                medicine.setRiskLevel(details.getRiskintensity());
                medicine.setRiskPoint(details.getRiskpoint());
                medicine.setUsingSuggestion(details.getUsingsuggestion());
            }
            return medicine;
        }
        else return null;
    }

    @Override
    public Medicine isWarn(String record) {
        if(warnMapper.selectByMedicineName(record)!=null){
            Medicine medicine=new Medicine();
            AvoidWarnDetails details=new AvoidWarnDetails();
            details=avoidWarnDetailsMapper.selectByMedicineName(record);
            if(details!=null){
                medicine.setName(details.getMedicinename());
                medicine.setRiskLevel(details.getRiskintensity());
                medicine.setRiskPoint(details.getRiskpoint());
                medicine.setUsingSuggestion(details.getUsingsuggestion());
            }
            return medicine;
        }
        else return null;
    }

    @Override
    public boolean isConflict(String medName1, String medName2) {
        ListConflicts conflicts=new ListConflicts();
        conflicts=conflictsMapper.selectByMedicineName(medName1,medName2);
        if(conflicts!=null){
           return true;
        }
        else return false;
    }

    @Override
    public AvoidWarnDetails detailsInfo(String record) {
        AvoidWarnDetails details=new AvoidWarnDetails();
        details=avoidWarnDetailsMapper.selectByMedicineName(record);
        return details;
    }


}
